#!/bin/bash
#Author:Jeakin
#Create Date:2015.09.20

export LANG=en_US.UTF-8
echo ========导入环境变量========#
HOME="/Users/admin/"
sourcePath=${HOME}'Desktop/yixia/mptlive'
project="MPTLive"
exportPath=${HOME}'Desktop/Live'
# webPath="/Library/WebServer/Documents/miaopai/"
webPath=${HOME}'Desktop/Live'
config="Release"
infoPlist=${sourcePath}/${project}'/Info.plist'
export SRCROOT=.;
export CONFIGURATION_BUILD_DIR=${exportPath}/Release-iphoneos
export UNLOCALIZED_RESOURCES_FOLDER_PATH=${project}'.app'
export INFOPLIST_FILE=$infoPlist
export CONFIGURATION="Debug"

tmpPwd=`pwd`
echo ========进入${sourcePath}========#
cd ${sourcePath}
echo ========更新GIT========#
#git pull
# # > /dev/null
# echo ========移出PODS========#
#rm -rf Podfile.Lock
#rm -rf Pods
# echo ========更新PODS========#
#pod update
# # > /dev/null
#
# # bundleVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" $infoPlist`
# # bundleIdentifier=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" $infoPlist`
# # bundleBuildVersion=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" $infoPlist`
#
 echo ========编译代码========#
 xcodebuild  -workspace ${project}.xcworkspace -scheme $project  -configuration $config clean build SYMROOT=${exportPath} CODE_SIGN_IDENTITY="iPhone Distribution: Xuan Yi xia Technology Co., LTD." PROVISIONING_PROFILE="c02f018b-faa5-4c11-84ac-777361599102" 
 #>~/a.txt
#  # > /dev/null
#
echo ========替换图标========#
${tmpPwd}/iconVersioning.sh
#  # > /dev/null
echo ========重新签名========#
# # # codesign -f -s "iPhone Distribution: Xuan Yi xia Technology Co., LTD." /Users/Jeakin/work/PinkCommunity_Build/build/Release-iphoneos/$project.app/ResourceRules.plist /Users/Jeakin/work/PinkCommunity_Build/build/Release-iphoneos/$project.app
codesign --force --sign C06D10070965C7D177FA93BECDFAC1EB274AF31A --entitlements ${tmpPwd}/${project}.app.xcent --timestamp=none ${exportPath}/${config}-iphoneos/${project}.app
# # > /dev/null
#
echo ========打包ipa========#
# # # # codesign -f -s "iPhone Distribution: Xuan Yi xia Technology Co., LTD." /Users/Jeakin/work/PinkCommunity_Build/build/Release-iphoneos/$project.app/ResourceRules.plist /Users/Jeakin/work/PinkCommunity_Build/build/Release-iphoneos/$project.app
xcrun -sdk iphoneos PackageApplication -v ${exportPath}/${config}-iphoneos/${project}.app -o ${exportPath}/${config}-iphoneos/${project}.ipa
#  # > /dev/null
# --sign C06D10070965C7D177FA93BECDFAC1EB274AF31A


echo ========创建WEB目录========#
mkdir -p ${webPath}/ipa/$(date +"%m")
mkdir -p ${webPath}/dsym/$(date +"%m")
echo ========转移IPA========#
name_formate=$(date +%Y-%m-%d-%H-%M-%S)
mv  ${exportPath}/${config}-iphoneos/${project}.ipa ${webPath}/ipa/$(date +"%m")/${project}${name_formate}.ipa
zip -r ${exportPath}/${config}-iphoneos/${project}.app.dSYM.zip ${exportPath}/${config}-iphoneos/${project}.app.dSYM
mv 	${exportPath}/${config}-iphoneos/${project}.app.dSYM.zip ${webPath}/dsym/$(date +"%m")/${project}${name_formate}.dSYM.zip







#echo ========上传NB========#
#expect -c "
#set timeout 1200;
#spawn /usr/bin/scp  ${webPath}/ipa/$(date +"%m")/${project}${name_formate}.ipa nb@nb.yixia.com:/Library/WebServer/Documents/miaopai/ipa/$(date +"%m")
#expect {
#	\"*yes/no*\" {send \"yes\r\"; exp_continue}
#	\"*Password*\" {send \"miaopai2016,nb\r\";}
#}
#expect eof;"





#快捷查看系统中能用来对代码进行签名的证书
# security find-identity -v -p codesigning



# git config --global credential.helper osxkeychain



